package cn.stylefeng.guns.modular.business.frequency.cmcompany.mapper;

import cn.stylefeng.guns.modular.business.frequency.cmcompany.model.param.CompanyDTO;
import cn.stylefeng.guns.modular.business.frequency.cmcompany.model.param.UnCheckCompanyVO;
import cn.stylefeng.guns.modular.business.frequency.cmcompany.model.result.CompanyVO;
import cn.stylefeng.guns.modular.business.frequency.cmcompany.model.result.PkgCompany;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.stylefeng.guns.modular.business.frequency.cmcompany.entity.CmCompany;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 通讯录表 Mapper 接口
 *
 * @author yujie
 * @date 2023/05/09 17:17
 */
public interface CmCompanyMapper extends BaseMapper<CmCompany> {

    Page<PkgCompany> getCompanyListPage(@Param("page") Page<Object> defaultPage, @Param("companyDTO") CompanyDTO companyDTO, @Param("list") List<Long> userId, @Param("tenantId") Long tenantId);

    PkgCompany getTableSummary(@Param("companyDTO") CompanyDTO companyDTO, @Param("list") List<Long> list, @Param("tenantId") Long tenantId);

    int countByName(@Param("name") String name, @Param("id") Long id, @Param("tenantId") Long tenantId);

    int countByPhone(@Param("phone") String phone, @Param("id") Long id, @Param("tenantId") Long tenantId);

    CompanyVO getCompanyVOById(@Param("id") String id);

    void deleteCompany(@Param("id") String id);

    @Update("update cm_company set has_check = 1 where id = #{id}")
    void updateHasCheck(@Param("id") String id);

    List<UnCheckCompanyVO> getHasCheckCompanyList(@Param("tenantId") Long tenantId);

    @Select("select id,name from cm_company where name = #{companyName} and tenant_id = #{tenantId}")
    CmCompany getByName(@Param("companyName") String companyName, @Param("tenantId") Long tenantId);

    List<Long> getCompanyIdList(@Param("list") List<Long> userId);

    void updateLastOrderTime(@Param("id") Long id);

    void updateLastTransportTime(@Param("id") Long companyId);

}